<?php
/**
 * Created by PhpStorm.
 * User: function
 * Date: 2018-05-02
 * Time: 10:18
 */

namespace app\admin\controller;
use app\common\controller\Admin;
use app\common\logic\AdLogic;
class Ad extends Admin
{
    public function index()
    {
        
        $logic = new AdLogic();
        $params = paramForm();
        
        if (\think\Request::instance()->isAjax()) {
            $params['paginate'] = true;
            $logic->setValue('order','id desc');
            $logic->setValue('with','place,seller');
            
            if (isset($params['title'])){
                $params['title'] = array('like','%'.$params['title'].'%');
            }
    
            //申请时间
            if(isset($params['start_time'])&&isValid($params['start_time'])){
        
                $startTime = strtotime($params['start_time']);
                if(!isValid($startTime)){
                    error('开始时间格式错误');
                }
        
                if(isset($params['end_time'])&&isValid($params['end_time'])){
            
                    $endTime = strtotime($params['end_time'])+86400;
                    if(!isValid($endTime)){
                        error('截止时间格式错误');
                    }
            
                }else{
                    $endTime = time();//如果不传就是获取当天的
                }
        
                $filter['create_time'] = array(array('EGT',$startTime),array('ELT',$endTime),'and');
        
            }
            
            
            $lists = $logic->getList($params);
            
            success($lists);
        } else {
            return $this->fetch();
        }
        
    }
    
    public function edit($id){
        $logic = new AdLogic();
        $logic->setValue('with','place,seller');
        $ad = $logic->findModel($id);
        $this->assign('model',$ad);
        return $this->fetch();
    }
    
    
}